{% extends 'mobile/base.html' %}

{% set styles = ('mobile-products',) %}
{% set scripts = ('mobile-products',) %}
{% set classes = 'documents' %}
{% if subtopic %}
  {% set headline = pgettext('DB: products.Topic.title', subtopic.title) %}
{% else %}
  {% set headline = pgettext('DB: products.Topic.title', topic.title) %}
{% endif %}
{% set title = headline + ' | ' + _('{product} Help')|f(product=pgettext('DB: products.Product.title', product.title)) %}
{% if subtopic %}
  {% set return_url = url('products.documents', product_slug=product.slug, topic_slug=topic.slug) %}
  {% set canonical_url = canonicalize(model_url=subtopic.get_absolute_url()) %}
{% else %}
  {% set return_url = url('products.product', slug=product.slug) %}
  {% set canonical_url = canonicalize(model_url=topic.get_absolute_url()) %}
{% endif %}

{% block after_header %}
{% endblock %}

{% block content %}
  {% if subtopic %}
    <div class="filter-bar">
      <a class="return-link" href="{{ return_url }}">
        {{ _('Back to:') }} {{ pgettext('DB: products.Topic.title', topic.title) }}
      </a>
    </div>
  {% else %}
    <div class="filter-bar">
      <a class="return-link" href="{{ return_url }}">
        {{ _('Back to:') }} {{ pgettext('DB: products.Product.title', product.title) }}
      </a>
    </div>
  {% endif %}

  <ul class="document-list">
    {% if not subtopic and subtopics %}
      {# only show subtopics on the parent topic page #}
      {% for subtopic in subtopics %}
        <li>
          <a href="{{ url('products.subtopics', product_slug=product.slug, topic_slug=topic.slug, subtopic_slug=subtopic.slug) }}"
          data-event-category="link click" data-event-action="subtopic" data-event-label="{{ subtopic.title }}">
            {{ pgettext('DB: products.Topic.title', subtopic.title) }}
          </a>
        </li>
      {% endfor %}
    {% endif %}
    {% for document in documents %}
      <li>
        <a class="cf" href="{{ document['url'] }}" data-event-category="link click"
        data-event-action="document" data-event-label="{{ document['document_title'] }}">{{ document['document_title'] }}</a>
      </li>
    {% endfor %}
    {% if product.questions_enabled(request.LANGUAGE_CODE) %}
      <li class="community-support">
        <a href="{{ url('wiki.document', 'get-community-support') }}">
          {{ _('Get community support') }}
        </a>
      </li>
    {% endif %}
  </ul>

  {% if fallback_documents %}
    <h2>{{ _('In English') }}</h2>
    {% for document in fallback_documents %}
      {% if loop.first %}<ul class="document-list">{% endif %}
      <li>
        <a href="{{ document['url']|replace('/'+ settings.WIKI_DEFAULT_LANGUAGE +'/', '/' + request.LANGUAGE_CODE + '/') }}">{{ document['document_title'] }}</a>
      </li>
      {% if loop.last %}</ul>{% endif %}
    {% endfor %}
  {% endif %}
{% endblock %}
